package com.aidong.myprofile.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.aidong.myprofile.biz.AidongSharingBiz;
import com.aidong.util.ReadPropertiesUtil;

/**
 * 分享至其它用户，将信息显示在HTML5页面上
 * @author user
 *
 */
@ParentPackage("json")
@Namespace("/")
public class AidongSharingAction {
	
	private AidongSharingBiz aidongSharingBiz;
	
	@Autowired
	public void setAidongSharingBiz(AidongSharingBiz aidongSharingBiz) {
		this.aidongSharingBiz = aidongSharingBiz;
	}

	private int id;
	
	public void setId(int id) {
		this.id = id;
	}

	Map<String, Object> map;
	
	@JSON
	public Map<String, Object> getMap() {
		return map;
	}

	/**
	 * 活动分享
	 * @return
	 */
	@Action(value="getcampaignsharing",results={@Result(name="succ",type="json",params={"root","map"})})
	public String getCampaignSharing(){
		map = new HashMap<String, Object>();
		try {
			Map<String, Object> campaginMap = aidongSharingBiz.getCampaginOne(id);
			campaginMap.put("bigUrl", ReadPropertiesUtil.getIMGREAD(campaginMap.get("bigUrl")));
			campaginMap.put("brandUrl", ReadPropertiesUtil.getIMGREAD(campaginMap.get("brandUrl")));
			map.put("campagin", campaginMap);
			return "succ";
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
	
	/**
	 * 场馆分享
	 * @return
	 */
	@Action(value="getstoresharing",results={@Result(name="succ",type="json",params={"root","map"})})
	public String getStoreSharing(){
		map = new HashMap<String, Object>();
		try {
			Map<String, Object> storeMap = aidongSharingBiz.getStoreOne(id);
			storeMap.put("bannerUrl", ReadPropertiesUtil.getIMGREAD(storeMap.get("bannerUrl")));
			storeMap.put("brandUrl", ReadPropertiesUtil.getIMGREAD(storeMap.get("brandUrl")));
			map.put("store", storeMap);
			return "succ";
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
	
	/**
	 * 团操课程分享
	 * @return
	 */
	@Action(value="getcoursesharing",results={@Result(name="succ",type="json",params={"root","map"})})
	public String getCourseSharing(){
		map = new HashMap<String, Object>();
		try {
			Map<String, Object> courseMap = aidongSharingBiz.getCourseOne(id);
			courseMap.put("bannerUrl", ReadPropertiesUtil.getIMGREAD(courseMap.get("bannerUrl")));
			courseMap.put("courseUrl", ReadPropertiesUtil.getIMGREAD(courseMap.get("courseUrl")));
			map.put("course", courseMap);
			return "succ";
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
	
	/**
	 * 私教课程分享
	 * @return
	 */
	@Action(value="getcoachsharing",results={@Result(name="succ",type="json",params={"root","map"})})
	public String getCoachSharing(){
		map = new HashMap<String, Object>();
		try {
			Map<String, Object> coachMap = aidongSharingBiz.getCoachOne(id);
			coachMap.put("bannerUrl", ReadPropertiesUtil.getIMGREAD(coachMap.get("bannerUrl")));
			coachMap.put("coachUrl", ReadPropertiesUtil.getIMGREAD(coachMap.get("coachUrl")));
			map.put("coach", coachMap);
			return "succ";
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
	
	/**
	 * 供应商规则分享
	 * @return
	 */
	@Action(value="getmealrulesharing",results={@Result(name="succ",type="json",params={"root","map"})})
	public String getMealRuleSharing(){
		map = new HashMap<String, Object>();
		try {
			Map<String, Object> foodMap = aidongSharingBiz.getMealRuleOne(id);
			foodMap.put("bigUrl", ReadPropertiesUtil.getIMGREAD(foodMap.get("bigUrl")));
			foodMap.put("brandUrl", ReadPropertiesUtil.getIMGREAD(foodMap.get("brandUrl")));
			map.put("food", foodMap);
			return "succ";
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 0);
			map.put("msg", "系统异常");
			return "succ";
		}
	}
}
